package com.df.bpm.utils.businessViewerV2.entityType;

import com.df.bpm.utils.businessViewerV2.Main;
import com.df.common.utils.CommonUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.List;

public class C_entityType {

    static Db_entityType database=new Db_entityType();

    static void editTypeDesc(JTable iTable, int row, List<M_entityType> list) {
        String oldValue=""+iTable.getValueAt(row, 2);
        String tips="请输入类型名称：";
        String newValue= (String) JOptionPane.showInputDialog(null, tips, "类型名称", JOptionPane.PLAIN_MESSAGE, null, null, oldValue);
        if(newValue!=null && !newValue.isEmpty() && !oldValue.equals(newValue)){
            iTable.setValueAt(newValue, row, 2);
            M_entityType temp = list.get(row)
                    .setName(newValue);
            if(newValue.equals("-")){
                if(CommonUtils.varIsNotBlank(temp.getEntityTypeIndex())){
                    if(database.delete(temp.getEntityTypeIndex())>0){
                        list.remove(row);
                        DefaultTableModel model=(DefaultTableModel)(iTable.getModel());
                        model.removeRow(row);
                    }
                }
            }else {
                database.update(temp);
            }
        }
    }

    public static List<M_entityType> search(List<JTextField> fields) {
        M_entityType temp=new M_entityType();
        if (CommonUtils.varIsNotBlank(fields.get(0).getText())) {
            temp.setName(fields.get(0).getText());
        }
        return database.getList4Like(temp);
    }

    public static M_entityType selectOne() throws Exception {
        V_entityType vType=new V_entityType();
        vType.repaint();
        vType.search();
        vType.setVisible(true);

        return vType.selectResult;
    }

    public static void main(String[] args) throws Exception {
        Main.getScreenMaxSize();
        String strType=selectOne().toString();
        System.out.println(strType);
    }
}
